package com.hhf.rpa.config;

import com.hhf.rpa.file.config.FileConfig;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class MvcConfig implements WebMvcConfigurer {

    @Autowired
    private LogfileConfig logfileConfig;
    @Autowired
    private FileConfig fileConfig;

    /**
     * 静态资源地址映射
     * @param registry
     */
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        // 解决静态资源无法访问
        registry.addResourceHandler("/**").addResourceLocations("classpath:/static/").addResourceLocations("classpath:/templates/");
        registry.addResourceHandler("/static/**").addResourceLocations("classpath:/static/");
        registry.addResourceHandler("/webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/").resourceChain(true);
        registry.addResourceHandler("/logs/**").addResourceLocations(logfileConfig.getPath());
        registry.addResourceHandler("/images/**").addResourceLocations("file:"+fileConfig.getStoragePath());
    }

}

